
-- 跨服精英赛 赛季信息
local CSEliteMatchSeasonInfo = class("CSEliteMatchSeasonInfo")
local Task = require("app.public.dao.Task")
local UserBaseInfo = require("app.public.dao.UserBaseInfo")

function CSEliteMatchSeasonInfo:ctor(data)
    if data then
        self:read(data)
    end
end

function CSEliteMatchSeasonInfo:read(msg)
    self.playInfo = {} -- 玩法信息
    if msg.playInfos then
        for i = 1, #msg.playInfos do
            local info = msg.playInfos[i]
            local warConf = GD:getEliteMatchById(info.playId)
            local limitReward = string.split(warConf.limitReward, "|")
            info.conf = warConf
            info.todayRewardLimit = tonumber(limitReward[3])
            self.playInfo[i] = info
        end
        table.sort(self.playInfo, function(a, b)
            return a.playId < b.playId
        end)
    end

    self:readMatchInfo(msg.matchInfo) -- 匹配信息
end

function CSEliteMatchSeasonInfo:getPlayInfoById(id)
    for i, v in ipairs(self.playInfo) do
        if v.playId == id then
            return v
        end
    end
end

function CSEliteMatchSeasonInfo:readMatchInfo(info)
	local matchInfo = {}
	matchInfo.state = info.state
	matchInfo.startStamp = info.startStamp
	local teammates = {}
	for _, data in ipairs(info.teammates) do
		local baseInfo = UserBaseInfo.new(data)
		table.insert(teammates, baseInfo)
	end
	matchInfo.teammates = teammates
	self.matchInfo = matchInfo
end

function CSEliteMatchSeasonInfo:setState(state)
    self.matchInfo.state = state
end

function CSEliteMatchSeasonInfo:getState()
    return self.matchInfo.state
end

function CSEliteMatchSeasonInfo:getTeammates()
    return self.matchInfo.teammates
end

return CSEliteMatchSeasonInfo